<?php

class setting_addfrdModel extends Model
{
	private $tb='setting_addfrd';
	
	//设置用户被添加权限
	public function addDef($uid,$deftype=0,$question='')
	{
		if($this->db->insert($this->tb,array('uid'=>$uid,'deftype'=>$deftype,'question'=>$question)))
		{
			return $this->db->insert_id();
		}
		else
		{
			return false;
		}
	}
	//修改用户被添加权限
	public function setDef($uid,$data)
	{
		if($this->db->update($this->tb,$data,$uid))
		{
			return $this->db->affect_row();
		}
		else
		{
			return false;
		}
	}
	//获取用户被添加权限信息
	public function getDef($uid)
	{
		$sql="select * from $this->tb where uid=$uid";
		$rs=$this->db->getRow($sql);
		//有则返回，无则添加再返回
		if(!$rs)
		{
			$new=$this->addDef($uid);
			if($new)
			{
				return array('said'=>$new,'uid'=>$uid,'deftype'=>0,'question'=>'');
			}
			else
			{
				return false;
			}
		}
		else
		{
			return $rs;
		}
	}


}